#ifndef YHAIDA_HTTPRESPONSE_H
#define YHAIDA_HTTPRESPONSE_H

#include "../../server/base/Utils.h"

#include <stdio.h>
#include <map>
/*
   — 响应行/状态行 —
       HTTP/1.1 200 OK \r\n                               # HTTP协议版本 状态码 状态描述
   — 响应头 —
       Server: Tengine \r\n                               # 服务器名称
       Content-Type: text/html; charset=UTF-8 \r\n        # 内容类型
       Transfer-Encoding: chunked \r\n                    # 发送给客户端内容不确定内容长度，发送结束的标记是0\r\n, Content-Length表示服务端确定发送给客户端的内容大小，但是二者只能用其一。
       Connection: keep-alive \r\n                        # 和客户端保持长连接
       Date: Fri, 23 Nov 2018 02:01:05 GMT \r\n           # 服务端的响应时间
   — 空行 —
   — 响应体 —
       //...
*/
namespace yhaida
{
    class Buffer; //前向声明
    class HttpResponse
    {
    public:
        enum HttpStatusCode
        {
            kUnknown,
            k200Ok = 200,
            k301MovedPermanently = 301,
            k400BadRequest = 400,
            k404NotFound = 404,
        };

    public:
        HttpResponse() = default;
        ~HttpResponse() = default;
        explicit HttpResponse(bool close);
        void setStatusCode(HttpStatusCode code);
        void setStatusQuery(const std::string &message);

        void setContentType(const std::string &contentType);
        void setCloseConnection(bool on);
        bool closeConnection() const;

        void addHeader(const std::string &key, const std::string &value);
        void setBody(const std::string &body);

        void appendToBuffer(Buffer *output) const;

    private:
        bool _closeConnection;
        HttpStatusCode _stateCode;
        std::string _query;
        std::map<std::string, std::string> _headers;
        std::string _body;
    };
}
#endif